package org.example.cloudcommon.Qdrant;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.zhipu.ZhipuAiEmbeddingModel;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.qdrant.QdrantEmbeddingStore;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.example.cloudcommon.Langchain4J.ChatAssistant;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class QdrantConfig {
    /**
     * 创建Qdrant客户端
     * @return
     */
    @Bean
    public QdrantClient qdrantClient(){
        QdrantGrpcClient.Builder builder = QdrantGrpcClient.newBuilder(
                "192.168.66.99",
                6334,
                false);
        return new QdrantClient(builder.build());
    }

    /**
     * 存储向量地方
     * @return
     */
    @Bean
    public EmbeddingStore<TextSegment> embeddingStore(){
        return QdrantEmbeddingStore.builder()
                .host("192.168.66.99")
                .port(6334)
                .collectionName("testv")
                .build();
    }

    @Bean("MyEmbeddingModel")
    public EmbeddingModel embeddingModel(){
        return ZhipuAiEmbeddingModel.builder()
                .apiKey("2676fc8e80844f7a85b0ff5a10fc5083.1D4a1gQ38W46uCon")
                .callTimeout(Duration.ofSeconds(1000))
                .connectTimeout(Duration.ofSeconds(1000))
                .readTimeout(Duration.ofSeconds(1000))
                .writeTimeout(Duration.ofSeconds(1000))
                .build();
    }


    /*
    * var vectorParams = Collections.VectorParams.newBuilder()
     .setDistance(Collections.Distance.Cosine)
     .setSize(1024)
     .build();
qdrantClient.createCollectionAsync("testv", vectorParams);
    * */
}
